import Mock from 'mockjs';
import { getUrlParams } from './utils';

let userList = [
	{
		id: 1,
		name: '刘一',
		process: 42.2,
		endTime: '2019年09月02日',
		price: 75.99,
		salesRate: 52.2,
		salesStatus: 1
	},
	{
		id: 2,
		name: '陈二',
		process: 35.2,
		endTime: '2019年09月05日',
		price: 242.1,
		salesRate: 72.1,
		salesStatus: 1
	},
	{
		id: 3,
		name: '张三',
		process: 10.2,
		endTime: '2019年09月12日',
		price: 74.11,
		salesRate: 23.9,
		salesStatus: 0
	},
	{
		id: 4,
		name: '李四',
		process: 75.5,
		endTime: '2019年09月13日',
		price: 276.64,
		salesRate: 47.2,
		salesStatus: 0
	},
	{
		id: 5,
		name: '王五',
		process: 25.4,
		endTime: '2019年09月18日',
		price: 160.23,
		salesRate: 28.3,
		salesStatus: 1
	},
	{
		id: 6,
		name: '赵六',
		process: 9.8,
		endTime: '2019年09月20日',
		price: 219.52,
		salesRate: 24.4,
		salesStatus: 0
	}
];

Mock.setup({
	timeout: '300'
});

Mock.mock(RegExp('/test/page' + '.*'), 'get', req => {
	let { page, size, salesStatus = '', keyWord = '', id = '', name = '' } = getUrlParams(req.url);

	let list = userList
		.filter(e => {
			if (salesStatus !== '') {
				return e.salesStatus == salesStatus;
			}

			return e;
		})
		.filter(e => {
			if (id) {
				return e.id == id;
			}

			if (name) {
				return e.name.includes(name);
			}

			if (keyWord) {
				return e.id == keyWord || e.name.includes(keyWord);
			}

			return e;
		})
		.slice((page - 1) * size, page * size);

	let total = list.length;

	return {
		code: 1000,
		data: {
			list,
			pagination: {
				pageSize: size,
				total,
				current: page
			}
		}
	};
});

Mock.mock(RegExp('/test/info' + '.*'), 'get', req => {
	let { id } = getUrlParams(req.url);

	return {
		code: 1000,
		data: userList.find(e => e.id == id)
	};
});

Mock.mock(RegExp('/test/update' + '.*'), 'post', req => {
	let d = JSON.parse(req.body);

	userList = userList.map(e => {
		if (e.id == d.id) {
			return Object.assign(e, d);
		}

		return e;
	});

	return {
		code: 1000
	};
});

Mock.mock(RegExp('/test/add' + '.*'), 'post', req => {
	let d = JSON.parse(req.body);

	d.id =
		Math.max.apply(
			this,
			userList.map(e => e.id)
		) + 1;

	userList.push(d);

	return {
		code: 1000
	};
});

Mock.mock(RegExp('/test/delete' + '.*'), 'post', req => {
	let { ids } = JSON.parse(req.body);

	ids = ids.split(',').map(Number);

	console.log(ids);

	userList = userList.filter(e => !ids.includes(e.id));

	return {
		code: 1000
	};
});

Mock.mock(RegExp('/mock/admin/comm/permmenu' + '.*'), 'get', () => {
	return {
		code: 1000,
		message: 'success',
		data: {
			perms: [
				'sys:menu:add',
				'sys:menu:delete',
				'sys:menu:update',
				'sys:menu:page',
				'sys:menu:list',
				'sys:menu:info',
				'sys:user:add',
				'sys:user:delete',
				'sys:user:update',
				'sys:user:page',
				'sys:user:list',
				'sys:user:info',
				'sys:role:add',
				'sys:role:delete',
				'sys:role:update',
				'sys:role:page',
				'sys:role:list',
				'sys:role:info',
				'sys:log:page',
				'sys:log:clear',
				'sys:log:get-keep',
				'sys:log:set-keep',
				'sys:department:list',
				'sys:department:add',
				'sys:department:update',
				'sys:department:delete',
				'sys:department:order',
				'sys:user:move',
				'sys:info:record',
				'sys:task:add',
				'sys:task:delete',
				'sys:task:info',
				'sys:task:update',
				'sys:task:page',
				'sys:task:log',
				'sys:task:once',
				'sys:task:start',
				'sys:task:stop',
				'sys:param:add',
				'sys:param:info',
				'sys:param:update',
				'sys:param:delete',
				'sys:param:page',
				'sys:param:list'
			],
			menus: [
				{
					id: '48',
					parentId: '47',
					name: '文档',
					type: 1,
					icon: 'icon-favorfill',
					orderNum: 0,
					router: '/tutorial/doc',
					viewPath: 'https://docs.cool-admin.com/#/',
					keepAlive: 1
				},
				{
					id: '59',
					parentId: '17',
					name: '组织列表',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '60',
					parentId: '17',
					name: '新增组织',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '61',
					parentId: '17',
					name: '更新组织',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '62',
					parentId: '17',
					name: '删除组织',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '63',
					parentId: '17',
					name: '组织排序',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '65',
					parentId: '17',
					name: '用户转移',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '67',
					parentId: '66',
					name: '记录',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '71',
					parentId: '70',
					name: '新增',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '72',
					parentId: '70',
					name: '删除',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '73',
					parentId: '70',
					name: '修改',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '74',
					parentId: '70',
					name: '查看',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '75',
					parentId: '70',
					name: '立即执行',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '76',
					parentId: '70',
					name: '开始',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '77',
					parentId: '70',
					name: '暂停',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '79',
					parentId: '78',
					name: '参数列表',
					type: 1,
					icon: 'icon-menu',
					orderNum: 0,
					router: '/sys/param',
					viewPath: 'views/system/param/index.vue',
					keepAlive: 1
				},
				{
					id: '80',
					parentId: '79',
					name: '新增',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '81',
					parentId: '79',
					name: '修改',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '82',
					parentId: '79',
					name: '删除',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '83',
					parentId: '79',
					name: '查看',
					type: 2,
					icon: null,
					orderNum: 0,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '93',
					parentId: null,
					name: '工作台',
					type: 1,
					icon: 'icon-gongzuotai',
					orderNum: 0,
					router: '/homes',
					viewPath: 'Home.vue',
					keepAlive: 1
				},
				{
					id: '10',
					parentId: '8',
					name: '新增',
					type: 2,
					icon: null,
					orderNum: 1,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '17',
					parentId: '27',
					name: '用户列表',
					type: 1,
					icon: 'icon-user',
					orderNum: 1,
					router: '/sys/user',
					viewPath: 'views/system/user/index.vue',
					keepAlive: 1
				},
				{
					id: '18',
					parentId: '17',
					name: '新增',
					type: 2,
					icon: null,
					orderNum: 1,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '23',
					parentId: '22',
					name: '新增',
					type: 2,
					icon: null,
					orderNum: 1,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '27',
					parentId: '2',
					name: '权限管理',
					type: 0,
					icon: 'icon-permission',
					orderNum: 1,
					router: '/sys/pre',
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '29',
					parentId: '28',
					name: '请求日志',
					type: 1,
					icon: 'icon-log',
					orderNum: 1,
					router: '/sys/log',
					viewPath: 'views/system/log/index.vue',
					keepAlive: 0
				},
				{
					id: '30',
					parentId: '29',
					name: '权限',
					type: 2,
					icon: null,
					orderNum: 1,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '43',
					parentId: '45',
					name: 'crud 示例',
					type: 1,
					icon: 'icon-radioboxfill',
					orderNum: 1,
					router: '/crud',
					viewPath: 'views/test/crud.vue',
					keepAlive: 1
				},
				{
					id: '53',
					parentId: '1',
					name: '组件预览',
					type: 1,
					icon: 'icon-activityfill',
					orderNum: 1,
					router: '/ui-components',
					viewPath: 'views/workbench/ui-components',
					keepAlive: 1
				},
				{
					id: '70',
					parentId: '69',
					name: '任务列表',
					type: 1,
					icon: 'icon-radioboxfill',
					orderNum: 1,
					router: '/sys/task',
					viewPath: 'views/system/task/index.vue',
					keepAlive: 1
				},
				{
					id: '88',
					parentId: '87',
					name: '联盟号管理',
					type: 1,
					icon: 'icon-hotfill',
					orderNum: 1,
					router: '/account/union',
					viewPath: 'views/account/union/index.vue',
					keepAlive: 1
				},
				{
					id: '90',
					parentId: '85',
					name: '订单统计',
					type: 1,
					icon: 'icon-rank',
					orderNum: 1,
					router: '/order/order',
					viewPath: 'views/order/order/index.vue',
					keepAlive: 1
				},
				{
					id: '8',
					parentId: '27',
					name: '菜单列表',
					type: 1,
					icon: 'icon-menu',
					orderNum: 2,
					router: '/sys/menu',
					viewPath: 'views/system/menu/index.vue',
					keepAlive: 1
				},
				{
					id: '11',
					parentId: '8',
					name: '删除',
					type: 2,
					icon: null,
					orderNum: 2,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '19',
					parentId: '17',
					name: '删除',
					type: 2,
					icon: null,
					orderNum: 2,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '24',
					parentId: '22',
					name: '删除',
					type: 2,
					icon: null,
					orderNum: 2,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '28',
					parentId: '2',
					name: '系统监控',
					type: 0,
					icon: 'icon-monitor',
					orderNum: 2,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '45',
					parentId: '1',
					name: '组件库',
					type: 0,
					icon: 'icon-activityfill',
					orderNum: 2,
					router: '/ui-lib',
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '66',
					parentId: '28',
					name: '服务状态',
					type: 1,
					icon: 'icon-monitor',
					orderNum: 2,
					router: '/sys/perf',
					viewPath: 'views/system/perf/index.vue',
					keepAlive: 0
				},
				{
					id: '86',
					parentId: '86',
					name: '联盟',
					type: 0,
					icon: 'icon-newshotfill',
					orderNum: 2,
					router: '/account/union',
					viewPath: 'views/account/union/index.vue',
					keepAlive: 1
				},
				{
					id: '87',
					parentId: null,
					name: '账号管理',
					type: 0,
					icon: 'icon-newshotfill',
					orderNum: 2,
					router: '/account',
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '89',
					parentId: '85',
					name: '产品统计',
					type: 1,
					icon: 'icon-goodsfill',
					orderNum: 2,
					router: '/order/orderprocuct',
					viewPath: 'views/order/product/index.vue',
					keepAlive: 0
				},
				{
					id: '94',
					parentId: '87',
					name: '推广位管理',
					type: 1,
					icon: 'icon-activityfill',
					orderNum: 2,
					router: '/account/extension',
					viewPath: 'views/account/extension/index.vue',
					keepAlive: 1
				},
				{
					id: '12',
					parentId: '8',
					name: '修改',
					type: 2,
					icon: null,
					orderNum: 3,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '20',
					parentId: '17',
					name: '修改',
					type: 2,
					icon: null,
					orderNum: 3,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '22',
					parentId: '27',
					name: '角色列表',
					type: 1,
					icon: 'icon-role',
					orderNum: 3,
					router: '/sys/role',
					viewPath: 'views/system/role/index.vue',
					keepAlive: 1
				},
				{
					id: '25',
					parentId: '22',
					name: '修改',
					type: 2,
					icon: null,
					orderNum: 3,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '49',
					parentId: '45',
					name: 'Quill富文本',
					type: 1,
					icon: 'icon-radioboxfill',
					orderNum: 3,
					router: '/editor-quill',
					viewPath: 'views/test/editor-quill.vue',
					keepAlive: 1
				},
				{
					id: '69',
					parentId: '2',
					name: '任务管理',
					type: 0,
					icon: 'icon-weibiaoti4',
					orderNum: 3,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '84',
					parentId: '85',
					name: '推广位统计',
					type: 1,
					icon: 'icon-newshotfill',
					orderNum: 3,
					router: '/order/pid',
					viewPath: 'views/order/pid/index.vue',
					keepAlive: 1
				},
				{
					id: '85',
					parentId: null,
					name: '订单管理',
					type: 0,
					icon: 'icon-weibiaoti4',
					orderNum: 3,
					router: '/order',
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '95',
					parentId: '87',
					name: '员工管理',
					type: 1,
					icon: 'icon-myfill',
					orderNum: 3,
					router: '/account/staff',
					viewPath: 'views/account/staff/index.vue',
					keepAlive: 1
				},
				{
					id: '1',
					parentId: null,
					name: '组件库',
					type: 0,
					icon: 'icon-hotfill',
					orderNum: 4,
					router: '/',
					viewPath: '',
					keepAlive: 1
				},
				{
					id: '13',
					parentId: '8',
					name: '查询',
					type: 2,
					icon: null,
					orderNum: 4,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '21',
					parentId: '17',
					name: '查询',
					type: 2,
					icon: null,
					orderNum: 4,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '26',
					parentId: '22',
					name: '查询',
					type: 2,
					icon: null,
					orderNum: 4,
					router: null,
					viewPath: null,
					keepAlive: 0
				},
				{
					id: '78',
					parentId: '2',
					name: '参数配置',
					type: 0,
					icon: 'icon-repairfill',
					orderNum: 4,
					router: null,
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '91',
					parentId: '85',
					name: '员工统计',
					type: 1,
					icon: 'icon-myfill',
					orderNum: 4,
					router: '/order/employee',
					viewPath: 'views/order/employee/index.vue',
					keepAlive: 1
				},
				{
					id: '96',
					parentId: '87',
					name: '角色管理',
					type: 1,
					icon: 'icon-newfill',
					orderNum: 4,
					router: '/account/role',
					viewPath: 'views/account/role/index.vue',
					keepAlive: 1
				},
				{
					id: '2',
					parentId: null,
					name: '系统',
					type: 0,
					icon: 'icon-systemfill',
					orderNum: 5,
					router: '/sys',
					viewPath: null,
					keepAlive: 1
				},
				{
					id: '92',
					parentId: '85',
					name: '组织统计',
					type: 1,
					icon: 'icon-team',
					orderNum: 5,
					router: '/order/group',
					viewPath: 'views/order/group/index.vue',
					keepAlive: 1
				},
				{
					id: '47',
					parentId: null,
					name: '教程',
					type: 0,
					icon: 'icon-weibiaoti4',
					orderNum: 6,
					router: '/tutorial',
					viewPath: null,
					keepAlive: 1
				}
			]
		}
	};
});

Mock.mock(RegExp('/mock/admin/comm/person' + '.*'), 'get', () => {
	return {
		code: 1000,
		message: 'success',
		data: {
			id: '1',
			createTime: '2019-06-25 10:20:20',
			updateTime: '2019-11-12 09:40:27',
			departmentId: '1',
			name: '超级管理员',
			username: 'admin',
			passwordV: 1,
			nickName: '超管',
			headImg:
				'https://cool-admin-test.oss-cn-shenzhen.aliyuncs.com/20191112/66f601a0-04ed-11ea-a6c3-85aa43fd65db.gif',
			phone: '18000000000',
			email: '123456@qq.com',
			remark: '备注',
			status: 1,
			roleIdList: ['1'],
			departmentName: 'COOL-ADMIN'
		}
	};
});
